﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace GISCommon
{
    public partial class RCITS_MapIndexCtrl : UserControl
    {
        /// <summary>
        /// 描述：操作实现的类声明

        /// </summary>
        private GISCommon.Business.MapIndexHelper m_pIndexMap;

        /// <summary>
        /// 描述：索引图的矩形框大小比例系数
        /// </summary>
        private float m_fltZoomOutFactor = 3;

        /// <summary>
        /// 描述：构造函数

        /// </summary>
        public RCITS_MapIndexCtrl()
        {
            InitializeComponent();
            Initial();
        }

        /// <summary>
        /// 描述：主地图控件
        /// </summary>
        private ESRI.ArcGIS.Controls.AxMapControl m_pMainMapControl;
        /// <summary>
        /// 描述：主地图控件
        /// </summary>
        public ESRI.ArcGIS.Controls.AxMapControl MainMapControl
        {
            get { return m_pMainMapControl; }
            set 
            { 
                m_pMainMapControl = value;
                Initial();
            }
        }

        /// <summary>
        /// 描述：索引图的文件路径

        /// </summary>
        private string m_strIndexMapFilePath;
        /// <summary>
        /// 描述：索引图的文件路径

        /// </summary>
        public string IndexMapFilePath
        {            
            get { return m_strIndexMapFilePath; }
            set 
            { 
                m_strIndexMapFilePath =value;
                Initial();
            }
        }

        /// <summary>
        /// 描述：使控件功能为可用前的初始化工作
        /// </summary>
        public void Initial()
        {
            try
            {
                if (m_pMainMapControl == null)
                {
                    //MessageBox.Show("您还没有设置主地图控件！");
                    return;
                }
                if (m_strIndexMapFilePath == "")
                {
                    //MessageBox.Show("您还没有加载索引图！");
                    return;
                }
                if (!IndexMapControl.CheckMxFile(m_strIndexMapFilePath))
                {
                    //MessageBox.Show("索引图文件路径有误！");
                    return;
                }
                else
                {
                    IndexMapControl.LoadMxFile(m_strIndexMapFilePath);
                }
                m_pIndexMap = new GISCommon.Business.MapIndexHelper();
                m_fltZoomOutFactor = 3;
                m_pIndexMap.ZoomOutFactor = m_fltZoomOutFactor;
                m_pIndexMap.Initial(IndexMapControl, m_pMainMapControl);
            }
            catch(Exception ex)
            {
                SysCommon.Global.mainLog.Error("RCITS_MapIndexCtrl的Initial()出错", ex);
            }
        }

        /// <summary>
        /// 描述：使控件功能为可用前的初始化工作
        /// </summary>
        /// <param name="MainMapControl">主地图控件</param>
        /// <param name="IndexMapFilePath">索引图文件名路径</param>
        public void Initial(ESRI.ArcGIS.Controls.AxMapControl MainMapControl, string IndexMapFilePath)
        {
            try
            {
                m_pMainMapControl = MainMapControl;
                m_strIndexMapFilePath = IndexMapFilePath;

                Initial();
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("RCITS_MapIndexCtrl的Initial()出错", ex);
            }
        }

        /// <summary>
        /// 描述：索引图的矩形框大小比例系数
        /// </summary>
        public float ZoomInFactor
        {
            get { return m_fltZoomOutFactor; }
            set 
            { 
                m_fltZoomOutFactor = value;
                if (m_pIndexMap != null)
                {
                    m_pIndexMap.ZoomOutFactor = m_fltZoomOutFactor;
                }
            }
        }
    }
}
